//
//  PPNetworkHelper.swift
//  TableViewSwift
//
//  Created by 郭颢源 on 2020/9/19.
//  Copyright © 2020 lisonglin. All rights reserved.
//


import Alamofire
import KakaJSON
import SwiftyJSON
// MARK:- 方法枚举类型
enum MethodType {
    case get
    case post
}
class PPNetworkHelper {
    class func requestData(_ type : MethodType, URLString : String, parameters : [String : Any]? = nil, finishedCallback: @escaping (_ result : Any) -> ()) {
           
           // 1.获取类型
           let method = type == .get ? HTTPMethod.get : HTTPMethod.post
     
           // 2.发送网络请求
           AF.request(URLString, method: method, parameters: parameters).responseJSON { (response) in
               // 3.获取结果
//               guard let result = response.result else {
//                   print(response.result)
//                   return
//               }
               // 4.将结果回调出去
               finishedCallback(response)
           }

       }
    
//    func Request(_ shortURL: String, method: HTTPMethod, params: [String: Any]?, jsonResponse: @escaping (_ json: JSON) -> (Void)){
//        guard let user = SingleUserClas.shareInstance.userModel else {
//            AF.request(baseURL + shortURL, method: method , parameters: params).responseJSON { response in
//                // 判断数据是否存在
//                guard let dict = response.value else { return }
//                // 将数据转为字典
//                let json = JSON(dict)
//                guard json["resp_code"].stringValue == "000000" else {
//                    ShowView(json["resp_message"].stringValue)
//                    return
//                }
//                jsonResponse(json)
//            }
//            return
//        }
//        let headers = HTTPHeaders(["authToken": user.userToken])
//        AF.request(baseURL + shortURL, method: method, parameters: params, headers: headers).responseJSON { response in
//            // 判断数据是否存在
//            guard let dict = response.value else { return }
//            // 将数据转为字典
//            let json = JSON(dict)
//            guard json["resp_code"].stringValue == "000000" else {
//                ShowView(json["resp_message"].stringValue)
//                return
//            }
//
//            jsonResponse(json)
//        }
//    }

}
